import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import { fileURLToPath, URL } from "node:url";
import AutoImport from 'unplugin-auto-import/vite';
import Components from 'unplugin-vue-components/vite';
import { ElementPlusResolver } from 'unplugin-vue-components/resolvers';

export default defineConfig({
  plugins: [
    vue(),
    AutoImport({
      resolvers: [ElementPlusResolver()],
    }),
    Components({
      resolvers: [ElementPlusResolver()],
    }),
  ],
  server: {
    port: 12650,
    proxy: { 
      '/api': { 
        target: 'http://192.168.1.113:5002', 
        changeOrigin: true 
      } 
    }
  },
  resolve: {
    alias: {
      "@": fileURLToPath(new URL("./src", import.meta.url))
    }
  },
  build: {
    outDir: "dist",
    minify: "terser",
    target: "es2015",
    chunkSizeWarningLimit: 2000,
    terserOptions: {
      compress: {
        drop_console: false,
        drop_debugger: false
      }
    },
    rollupOptions: {
      output: {
        chunkFileNames: "js/[hash].js",
        entryFileNames: "js/[hash].js",
        assetFileNames(assetInfo) {
          if (assetInfo.name && assetInfo.name.endsWith(".css")) {
            return "css/[hash].css";
          }
          if ([".png", "jpg", ".jpge", ".webp", ".svg", ".gif"].some((ext) => assetInfo.name && assetInfo.name.endsWith(ext))) {
            return "images/[hash].[ext]";
          }
          return "assets/[hash].[ext]";
        }
      }
    }
  }
})
